﻿using System;
using System.Data;
using System.Collections.Generic;
using Clipper.Model;
using System.Collections.ObjectModel;
using Clipper.BLL;
using Clipper.DAL;

namespace Clipper.BLL
{
	/// <summary>
	/// Reagent
	/// </summary>
	public partial class Reagent
	{
		private readonly Clipper.DAL.Reagent dal=new Clipper.DAL.Reagent();
        DAL.DetectItems mDetectItemsDal = new DAL.DetectItems();

		public Reagent()
		{}
		#region  BasicMethod

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int reagentID)
		{
			return dal.Exists(reagentID);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(Clipper.Model.Reagent model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Clipper.Model.Reagent model)
		{
			return dal.Update(model);
		}

        /// <summary>
        /// 更新ISIpt试剂
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool UpdateISI(Clipper.Model.Reagent model)
        {
            return dal.UpdateISI(model);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int reagentID)
		{
			
			return dal.Delete(reagentID);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string reagentIDlist )
		{
			return dal.DeleteList(reagentIDlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Clipper.Model.Reagent GetModel(int reagentID)
		{
			return dal.GetModel(reagentID);
		}
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Clipper.Model.Reagent GetModelByBarcode(string barcode)
        {
            return dal.GetModelByBarcode(barcode);
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Clipper.Model.Reagent GetModelByReagentName(string reagentName)
        {
            return dal.GetModelByReagentName(reagentName);
        }
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public ObservableCollection<Clipper.Model.Reagent> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public ObservableCollection<Clipper.Model.Reagent> DataTableToList(DataTable dt)
		{
			ObservableCollection<Clipper.Model.Reagent> modelList = new ObservableCollection<Clipper.Model.Reagent>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				Clipper.Model.Reagent model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = dal.DataRowToModel(dt.Rows[n]);
					if (model != null)
					{
						modelList.Add(model);
					}
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			return dal.GetRecordCount(strWhere);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return dal.GetListByPage( strWhere,  orderby,  startIndex,  endIndex);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  BasicMethod
		#region  ExtensionMethod
        ///<summary>
        ///获得数据列表有检测项信息,有项目类型
        ///</summary>
        //public ObservableCollection<Clipper.Model.Reagent> GetFullDetectItemsInfoList(string strWhere)
        //{
        //    DataSet ds = dal.GetList(strWhere);
        //    ObservableCollection<Clipper.Model.Reagent> modelList = new ObservableCollection<Clipper.Model.Reagent>();
        //    int rowsCount = ds.Tables[0].Rows.Count;
        //    if (rowsCount > 0)
        //    {
        //        Clipper.Model.Reagent model;
        //        for (int n = 0; n < rowsCount; n++)
        //        {
        //            model = dal.DataRowToModel(ds.Tables[0].Rows[n]);
        //            if (model != null)
        //            {
        //               //model.DetectItem =Convert.ToString(mdetectItemsDal.GetModel(model.DetectItem)); 
                       
        //                modelList.Add(model);
        //            }
        //        }
        //    }
        //    return modelList;
        //}
        ///<summary>
        ///得到实体对象,有项目类型
        ///</summary>
        public Clipper.Model.Reagent GetItemsReagent(int reagentID)
        {
            Model.Reagent model= dal.GetModel(reagentID);
            if (model != null)
            {
                model.DetectItemModel = mDetectItemsDal.GetModel(model.DetectItem);
            }
            return model;
        }

        //public Clipper.Model.Reagent GetItemsReagentS(string reagentID)
        //{
        //    Model.Reagent model = dal.GetModel(reagentID);
        //    if (model != null)
        //    {
        //        model.DetectItemModel = mDetectItemsDal.GetModel(model.DetectItem);
        //    }
        //    return model;
        //}
		#endregion  ExtensionMethod
	}
}

